package LeetCode;

import java.util.LinkedList;
import java.util.Queue;

/**
 * @Author Kechelle
 * @Date 2020/9/11 1:00
 * @Version 1.0
 */
public class Code3 {
    public static int lengthOfLongestSubstring(String s) {
        Queue<Character> queue = new LinkedList<>();
        char[] chars = s.toCharArray();
        int res = 0;
        for (char c:chars){
            while (queue.contains(c)){
                queue.poll();
            }
            queue.add(c);
            res = Math.max(res,queue.size());
        }
        return res;
    }

    public static void main(String[] args) {
        String s = "abcabcbb";
        System.out.println(Code3.lengthOfLongestSubstring(s));
    }
}
